# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
import pymysql


class MysqlPipeline(object):
    def __init__(self):
        pass
        # 建立连接
        # self.conn = pymysql.connect(host="127.0.0.1",
        #                             port=3306,
        #                             db='films',
        #                             user='root',
        #                             passwd='root',
        #                             charset='utf-8',
        #                             use_unicode=True)  # 有中文要存入数据库的话要加charset='utf8'
        # # 创建游标
        # self.cursor = self.conn.cursor()

    def process_item(self, item, spider):
        pass
        # sql语句
        # insert_sql = """
        #         insert into film(title,creator,up_time,duration,region,score,evaluate_num,report_num,img_num,video_num) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
        #         """
        # 执行插入数据到数据库操作
        # self.cursor.execute(insert_sql, (
        #     item['title'], item['creator'], item['up_time'], item['duration'], item['region'], item['score'],
        #     item['evaluate_num'], item['report_num'], item['img_num'], item['video_num']))
        # 提交，不进行提交无法保存到数据库
        # self.conn.commit()
        # return item
